﻿using System;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using PMS;
using PMS.DanhMucChung;
using PMS.Resources;
using PMS.Win;
using PMS.ValidationRules;
using PMS.ReportViewer;
using PMS.Utils;

namespace PMS.ChucNang
{
    public partial class ChiTietNhapXuatSanPham : FormManualBase
    {
        public ChiTietNhapXuatSanPham()
        {
            InitializeComponent();
        }

        public ChiTietNhapXuatSanPham(string functionID)
            : base(functionID)
        {
            InitializeComponent();
            InitControls();
        }

        public void InitControls()
        {
            //cboeChiTiet.Properties.Items.Add("Chi tiết Nhập và Xuất");
            cboeChiTiet.Properties.Items.Add("Chi tiết Nhập");
            cboeChiTiet.Properties.Items.Add("Chi tiết Xuất");
            cboeChiTiet.SelectedIndex = 0;
        }
        

        private void btneMaSP_Click(object sender, EventArgs e)
        {
            try
            {
                ProductLookup form = new ProductLookup();
                if (form.ShowDialog() == DialogResult.OK)
                {
                    if (form.ProductSelected != null)
                    {
                        btneMaSP.EditValue = form.ProductSelected.MaThuoc;
                    }
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex);
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidateControls())
                {
                    String MaSP = DataConvertUltils.ToString(btneMaSP.EditValue);
                    int chitet = cboeChiTiet.SelectedIndex;
                    XtraForm form = new BaseForm();
                    if(chitet == 0)
                        form = new ChiTietNhapSanPhamViewer(MaSP, (DateTime?)dateTuNgay.EditValue, (DateTime?)dateDenNgay.EditValue);
                    else if (chitet == 1)
                        form = new ChiTietXuatSanPhamViewer(MaSP, (DateTime?)dateTuNgay.EditValue, (DateTime?)dateDenNgay.EditValue);
                    
                    form.WindowState = FormWindowState.Maximized;
                    form.StartPosition = FormStartPosition.CenterParent;
                    form.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex);
            }
        } 
    }
}